{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/technological/css/style.css">
    <link rel="stylesheet" href="../../static/public_file/css/DepartmentSelection.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .add_background {
            background: #A9A9A9;
        }
        tr td {
            height: 35px;padding-right: 5px;outline: none;
        }
        th {
            text-align: center;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
        #addForm {
            width: 800px;height: 620px;background: #F5F5F5;position: absolute;border: #dfdfdf solid 1px;margin: auto;border-radius: 3px;top: 50%;left: 50%;transform: translate(-50%, -50%);display: none;z-index: 10100;font-size: 0;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="/finance/data_export_list.html" style="color: #0b0b0b;">数据外导</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;">
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;margin-top: 20px;">
                        <tr style="margin-left: 1%;width: 100%;">
                            <td colspan="4" style="width: 100%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                <h3 id="form_name" style="letter-spacing: 8px;">京山市人民医院敏感信息数据外导申请表</h3>
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;width: 100%;">
                            <td colspan="4" style="width: 100%;border: #cfcfcf solid 0.5px;text-align: left;height: 35px;line-height: 35px;padding-left: 0.5%;background: #F5F5F5;color: #1E90FF;">
                                基本信息
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 1.5px;">
                                申&nbsp;&nbsp;&nbsp;&nbsp;请&nbsp;&nbsp;&nbsp;&nbsp;人
                            </td>
                            <td id="applicat"
                                style="width: 35%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ realname }}</td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;letter-spacing: 8px;">
                                申请科室
                            </td>
                            <td id="" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">{{ department }}
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;width: 100%;">
                            <td colspan="4" style="width: 100%;border: #cfcfcf solid 0.5px;text-align: left;height: 35px;line-height: 35px;padding-left: 0.5%;background: #F5F5F5;color: #1E90FF;">
                                申请详情
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                申&nbsp;&nbsp;请&nbsp;&nbsp;理&nbsp;&nbsp;由
                            </td>
                            <td id="application_reason" colspan="3" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;" contenteditable="true">
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                外&nbsp;&nbsp;导&nbsp;&nbsp;依&nbsp;&nbsp;据
                            </td>
                            <td id="external_guidance_basis" colspan="3" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;" contenteditable="true">
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 8px;border-bottom: none;">
                                数据类型
                            </td>
                            <td colspan="3" style="width: 85%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">
                                <input type="radio" name="data_type" value="seven"> 医保数据
                                <input type="radio" name="data_type" value="eight" style="margin-left: 20px;"> 市场监督审计
                                <input type="radio" name="data_type" value="one" style="margin-left: 20px;"> 诊疗信息
                                <input type="radio" name="data_type" value="two" style="margin-left: 20px;"> 财务数据
                                <input type="radio" name="data_type" value="three" style="margin-left: 20px;"> 资产数据
                                <input type="radio" name="data_type" value="four" style="margin-left: 20px;"> 人事信息
                                <input type="radio" name="data_type" value="five" style="margin-left: 20px;"> 药品信息
                                <input type="radio" name="data_type" value="six" style="margin-left: 20px;"> 其他信息
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;border-bottom: #cfcfcf solid 0.5px;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;border-bottom: none;">
                                纪&nbsp;&nbsp;委&nbsp;&nbsp;报&nbsp;&nbsp;备
                            </td>
                            <td id="" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">
                                <input type="radio" value="1" name="inspection_report"> 是
                                <input type="radio" value="0" name="inspection_report" style="margin-left: 20px;"> 否
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 8px;border-bottom: none;">
                                是否上会
                            </td>
                            <td id="" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;border-bottom: none;">
                                <input type="radio" value="1" name="meet_or_not"> 是
                                <input type="radio" value="0" name="meet_or_not" style="margin-left: 20px;"> 否
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="width: 95%;margin-left: 2.5%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main"></tbody>
                    </table>
                </div>
            </div>

        </div>

        <div id="selection-office" class="office-shade">
            <div id="office-model">
                <!-- 标题 -->
                <div id="office-title">
                    <h5 style="line-height: 40px;width: 15%;margin-left: 1%;display: inline-block;font-size: 14px;">选择科室</h5>
                    <span onclick="close_office_models()" style="float: right;line-height: 50px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
                </div>
                <hr>
                <div style="width: 55%;height: 350px;vertical-align: top;left: 0;display: inline-block;border-right: #cfcfcf solid 1px;">
                    <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                        <input id="search_data1" onkeydown="search_dep()" class="search-input" type="text" placeholder="搜索" autocomplete="off">
                    </div>
                    <div id="processed" style="width: 100%;height: 300px;overflow: auto;">
                        {% for company in company_list %}
                            <div style="width: 100%;height: 30px;line-height: 30px;font-size: 14px;color: #0b0b0b;">
                                <input class="check_box1" id="{{ company.id }}" type="checkbox" onclick="check_dep_ff('{{ company.name }}', '{{ company.id }}', false)"> {{ company.name }}
                            </div>
                        {% endfor %}
                    </div>
                </div>

                <div style="width: 43%;height: 360px;vertical-align: top;left: 0;display: inline-block;">
                    <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;font-size: 14px;">
                        已选择科室
                    </div>
                    <div id="processed_prople" style="width: 100%;height: 265px;overflow: auto;padding-left: 2%;">

                    </div>
                    <div style="width: 100%;height: 40px;text-align: center;">
                        <button onclick="summit_val()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #1E90FF solid 1px;background: #1E90FF;color: white;width: 80px;letter-spacing: 4px;font-size: 14px;">
                            提交
                        </button>
                        <button onclick="close_office_models()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #cfcfcf solid 1px;width: 80px;letter-spacing: 4px;margin-left: 15px;font-size: 14px;">
                            取消
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->
    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";

        };

        lay('#version').html('-v' + laydate.v);

        //执行一个laydate实例
        laydate.render({
            elem: '#contract_effect', //指定元素
            type: 'date',
            format: 'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#contract_off', //指定元素
            type: 'date',
            format: 'yyyy-MM-dd'
        });

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', '{{ uuid }}')
            form.append('source', 'sjwd')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function submit_data() {
            var administrative_table = document.getElementById('party_main');
            if (!administrative_table.children.length) {
                alert("请上传附件！");
                return false
            }
            var application_reason = document.getElementById('application_reason').innerText;
            var external_guidance_basis = document.getElementById('external_guidance_basis').innerText;
            var data_type = $("input[type=radio][name=data_type]:checked").val();
            var inspection_report = $("input[type=radio][name=inspection_report]:checked").val();
            var meet_or_not = $("input[type=radio][name=meet_or_not]:checked").val();

            if (!application_reason) {
                alert("请输入申请理由！");
                return false
            }

            var form = new FormData();
            form.append('application_reason', application_reason)
            form.append('external_guidance_basis', external_guidance_basis)
            form.append('data_type', data_type)
            form.append('inspection_report', inspection_report)
            form.append('meet_or_not', meet_or_not)
            form.append('fj_number', '{{ uuid }}')

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/finance/data_export_index.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/finance/data_export_list.html";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };

        }

        function save_data() {
            var application_reason = document.getElementById('application_reason').innerText;
            var external_guidance_basis = document.getElementById('external_guidance_basis').innerText;
            var data_type = $("input[type=radio][name=data_type]:checked").val();
            var inspection_report = $("input[type=radio][name=inspection_report]:checked").val();
            var meet_or_not = $("input[type=radio][name=meet_or_not]:checked").val();

            var form = new FormData();
            form.append('application_reason', application_reason)
            form.append('external_guidance_basis', external_guidance_basis)
            form.append('data_type', data_type)
            form.append('inspection_report', inspection_report)
            form.append('meet_or_not', meet_or_not)
            form.append('fj_number', '{{ uuid }}')

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            xhr.open('post', "/finance/data_export_draft.html", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("保存成功");
                            window.location = "/finance/data_export_list.html";
                            document.getElementById("loading").style.display = "none";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };

        }
    </script>
{% endblock %}



